using System;
using System.Diagnostics;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

namespace SilverMenu
{
	public abstract class GUIElement
	{
		public String Name = "";
		public Color Color = Color.White;
		public Rectangle Rect = Rectangle.Empty;
		public Vector2 Position = Vector2.Zero;
		public String Source = null;
		public bool HasTransitionTime = false;
		public float TransitionTime = 0;

		public abstract void Draw(SpriteBatch spriteBatch, ref Rectangle r);
	}

	public class SilverBackground : GUIElement
	{
		public object Texture;

		public override void Draw(SpriteBatch spriteBatch, ref Rectangle r)
		{
			Debug.Assert(Texture != null);
			spriteBatch.Draw((Texture2D)Texture, r, Color);
		}
	}

	public class SilverButton : GUIElement
	{
		public object Texture;
		public String FontSource;
		public object Font;
		public String Text;
	    public Vector2 Offset;
		public Color TextColor;
		public String NextPage;
		public String EventHandlerName;

        private Vector2 m_drawPos;

		public delegate void OnClickDelegate(SilverButton sender);
		public event OnClickDelegate OnClick;

		public SilverButton()
		{
			TextColor = Color.Black;
			m_drawPos = Vector2.Zero;
		}

		public override void Draw(SpriteBatch spriteBatch, ref Rectangle r)
		{
			//Debug.Assert(Texture != null);
            if(Texture != null)
                spriteBatch.Draw((Texture2D)Texture, r, Color);
			
			if (Font != null && !string.IsNullOrEmpty(Text))
			{
				m_drawPos.X = r.X + Offset.X;
				m_drawPos.Y = r.Y + Offset.Y;
				spriteBatch.DrawString((SpriteFont)Font, Text, m_drawPos, TextColor);
			}
		}

		public void InvokeOnClick()
		{
			if (OnClick != null)
				OnClick(this);
		}
	}

	public class SilverText : GUIElement
	{
		public String Text;
		public object Font;

		private Vector2 m_drawPos;

		public SilverText()
		{
			Color = Color.Black;
			m_drawPos = Vector2.Zero;
		}

		public override void Draw(SpriteBatch spriteBatch, ref Rectangle r)
		{
			Debug.Assert(Font != null && Text != null);

			m_drawPos.X = r.X;
			m_drawPos.Y = r.Y;
			spriteBatch.DrawString((SpriteFont)Font, Text, m_drawPos, Color);
		}
	}
}
